package com.pandas.community.Utils;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

public class CookieUtil {
    // request中含有cookie，根据cookie名查询cookie值
    public static String getValue(HttpServletRequest request, String name){
        if(request == null || name == null) throw new IllegalArgumentException("cookie相关查询，参数为空！");

        Cookie[] cookies = request.getCookies();
        if(cookies != null){
            for(Cookie cookie : cookies){
                if(cookie.getName().equals(name)){
                    return cookie.getValue();
                }
            }
        }
        return null;
    }
}
